﻿#ifndef __SS_CONTEXT_H__
#define __SS_CONTEXT_H__
#ifdef _WIN32
#include <windows.h>
#else
#include <ucontext.h>
#include <unistd.h>
#endif

namespace StarSeeker
{

enum CONTEXT_STATE :char
{
	CS_NULL = 0,
	CS_READY,
	CS_RUNING,
	CS_SUSPEND,
	CS_END
};

class ssContext
{
public:
	ssContext();
	virtual ~ssContext();
	void Create(void* mainContext, unsigned int stackSize=512000);
	void Run();
	void YieldReturn();
	CONTEXT_STATE State();
	void Stop();
private:
#ifdef _WIN32
	static void WINAPI ContextFunc(PVOID param);
#else
	static void ContextFunc(void* param);
#endif
protected:
	virtual void ContextMemberFunc();
private:
#ifdef _WIN32
	LPVOID			m_main;
	LPVOID			m_context;
#else
	ucontext_t*		m_main;
	ucontext_t		m_context;
	void*			m_stack;
#endif
	CONTEXT_STATE	m_state;
	unsigned int	m_stackSize;
};

}
#endif
